package com.example.featuresdk.viewmodel

import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.navigation.NavHostController
import com.example.featuresdk.core.NavigationMediator
import com.example.featuresdk.core.FeatureCategory
import dagger.hilt.android.lifecycle.HiltViewModel
import java.util.stream.Collectors
import javax.inject.Inject

@HiltViewModel
class NavigationViewModel @Inject constructor(val mediator: NavigationMediator): ViewModel() {

    var screenWithDp = 0
    var screenHeightDp = 0
    val appHeaderBarHeightDp = 40
    val appBottomBarHeightDp = 50
    val appBottomSpacerHeightDp = 2

    val headerIconSizeDp = 34

    val appBodyHeightDp by lazy {
        if (screenWithDp == 0 || screenHeightDp == 0) throw RuntimeException("screenWithDp or screenHeightDp can't be 0")

        screenHeightDp - appHeaderBarHeightDp - appBottomBarHeightDp - appBottomSpacerHeightDp
    }

    lateinit var navHostController: NavHostController

    val features by lazy {
        mutableStateOf(mediator.features)
    }

    val homeFeatureKey by lazy {
        mutableStateOf(mediator.homeFeatureKey)
    }

    val primaryFeatures by lazy {
        mediator.features.filterValues { feature -> feature.featureCategory() == FeatureCategory.Primary }
            .values.stream().collect(Collectors.toList())
    }

    val headerFeatures by lazy {
        mediator.features.filterValues { feature -> feature.featureCategory() == FeatureCategory.Header }.values
    }

    val selectedPrimaryFeatureTabIndex = mutableStateOf(0)
    val selectedPrimaryFeatureTitle = mutableStateOf("")
    var activeContextualFeatureKey = mutableStateOf("")
}